//
//  OnboardingViewController.swift
//  placepic
//
//  Created by elesahich on 2020/09/05.
//  Copyright © 2020 elesahich. All rights reserved.
//

import UIKit

class OnboardingViewController: UIViewController {

    @IBOutlet weak var onboardingLabel: UILabel!
    @IBOutlet weak var findButton: UIButton!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupMainView()
        setupNavigationBar()
    }
    @IBAction func sendButtonAction(_ sender: Any) {
        
        guard let vc = storyboard?.instantiateViewController(identifier: "SignInUpViewController") as? SignInUpViewController else {
            fatalError()
        }
        
        navigationController?.pushViewController(vc, animated: true)
    }
}

extension OnboardingViewController {
           
    private func setupMainView() {
        onboardingLabel.text = "친구들과 함께\n최애장소를 공유해보세요!"
        onboardingLabel.font = .boldSystemFont(ofSize: 18)
        
        findButton.layer.cornerRadius = 8
        findButton.backgroundColor = UIColor.warmPink
        findButton.setTitle("내 그룹 찾아보기", for: .normal)
        findButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
        findButton.setTitleColor(UIColor.white, for: .normal)
    }
    
    private func setupStatusBar() {
        if #available(iOS 13.0, *) {
            
            var statusBarHeight: CGFloat = 0
            if let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) {
                statusBarHeight = window.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
            }
            
            let statusbarView = UIView()
            statusbarView.backgroundColor = UIColor.warmPink
            statusbarView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: statusBarHeight)
            view.addSubview(statusbarView)
            
            statusbarView.translatesAutoresizingMaskIntoConstraints = false
       
            let constraints = [
                statusbarView.heightAnchor.constraint(equalToConstant: statusBarHeight),
                statusbarView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1.0),
                statusbarView.topAnchor.constraint(equalTo: view.topAnchor),
                statusbarView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
            ]
            
            NSLayoutConstraint.activate(constraints)
        } else {
            let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
            statusBar?.backgroundColor = UIColor.red
        }
    }
    
    private func setupNavigationBar() {
        guard let navigationBar = self.navigationController?.navigationBar else { return }
        
        navigationBar.isTranslucent = true
        navigationBar.backgroundColor = UIColor.clear
        navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        navigationBar.shadowImage = UIImage()
            
        navigationItem.leftBarButtonItem = nil
    }
}

